﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Data; 
using ReflectionStudio.Core.Events;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Input;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class TVKSS 
    {
        #region ==FROMDATE===========
        public static readonly DependencyProperty FROMDATEProperty = DependencyProperty.Register("FROMDATE",
            typeof(string), typeof(TVKSS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFROMDATEChanged));
        public string FROMDATE
        {
            get
            {
                return (string)GetValue(FROMDATEProperty);
            }
            set
            {
                SetValue(FROMDATEProperty, value);
            }
        }
        private static void OnFROMDATEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TVKSS;
            if (src != null)
            {
                src.FROMDATE = (string)e.NewValue;
            }
        }
        #endregion

        #region ==ENDDATE===========
        public static readonly DependencyProperty ENDDATEProperty = DependencyProperty.Register("ENDDATE",
            typeof(string), typeof(TVKSS),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnENDDATEChanged));
        public string ENDDATE
        {
            get
            {
                return (string)GetValue(ENDDATEProperty);
            }
            set
            {
                SetValue(ENDDATEProperty, value);
            }
        }
        private static void OnENDDATEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TVKSS;
            if (src != null)
            {
                src.ENDDATE = (string)e.NewValue;
            }
        }
        #endregion

        ITXEXRPT ITXEXRPT;

      
        public TVKSS()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVKPOS();
            this.DataContext = MV;
            MESSAGES += "VKKNEW;VVRELOAD;VVTCHG;VKPCHK;WDCHG;"; 
            InitializeComponent();
            FROMDATE = DateTime.Today.ToShortTimeString();
            ENDDATE = DateTime.Today.ToShortTimeString();
           
        }
      
        public override void Window_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
           
        }
      
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
           // base.vwMaster_CurrentChanged(sender, e);
           
        }

        public override void QueryCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            //if (FROMDATE==null)
            //{
            //    MessageBox.Show("请选择开始日期");
            //    return;
            //}
            // else if (ENDDATE==null)
            //{
            //    MessageBox.Show("请选择结束日期");
            //}
            dwData = TBMain.NewRow();
            //DataRow dwData = null;
            dwData["VKPAENDDAT"] = FROMDATE;
            dwData["VKPNEUDAT"] = ENDDATE;
            try
            {
            SResult = TMV.QVKP28(dwData);
            MergeData(SResult, false);
            base.QueryCommand(sender, e);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        
        }
        private void btnSendToExcel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ITXEXRPT == null)
                {
                    ITXEXRPT = new ITXEXRPT();
                    ITXEXRPT.Root = "C:\\IntexReport";
                    ITXEXRPT.strCompany = app.company;
                    ITXEXRPT.PrintType = "OpenExcel";
                }
                ITXEXRPT.dsSource = new DataSet();
                ITXEXRPT.dsSource.Merge(MV.SetProd);
                //ITXEXRPT.dsSource.Merge(Se.Env);

                ITXEXRPT.DocType = "JLTVKSS";

                ITXEXRPT.strExcelFile = @"JLT\JLTVKSS.xls";
                string filename = ITXEXRPT.WriteExcelReport();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void FROM_DATE_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                //FROMDATE = "";
                FROMDATE = Helpers.Helper.GetDate(sender);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        private void END_DATE_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                //ENDDATE = "";
                ENDDATE = Helpers.Helper.GetDate(sender);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        
    }
}
